//
//  THFlowEarnReportVC.m
//  YJB
//
//  Created by 中电大维 on 2017/1/17.
//  Copyright © 2017年 YJB. All rights reserved.
//

#import "THFlowEarnReportVC.h"

@interface THFlowEarnReportVC ()

@end

@implementation THFlowEarnReportVC
{
    UIButton *_advertButton;
    UIButton *_eroticaButton;
    UIButton *_illegalButton;
    UIButton *_submitButton;
    NSMutableString *_content;
    NSArray *_arrays;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _content = [[NSMutableString alloc] init];
    _arrays = [[NSArray alloc] initWithObjects:@"垃圾广告",@"淫秽色情",@"虚假信息、违法乱纪", nil];
    self.title = @"举报";
    self.view.backgroundColor = kUIColorFromRGB(0xeeeeee);
    [self createView];
}

-(void)selectType:(UIButton *)button
{
    _content = _arrays[button.tag-1];
    switch (button.tag) {
        case 1:
            _advertButton.selected = YES;
            _eroticaButton.selected = NO;
            _illegalButton.selected = NO;
            
            break;
        case 2:
            _advertButton.selected = NO;
            _eroticaButton.selected = YES;
            _illegalButton.selected = NO;
            break;
        case 3:
            _advertButton.selected = NO;
            _eroticaButton.selected = NO;
            _illegalButton.selected = YES;
            break;
    }
}
-(void)submitClick:(UIButton *)button
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    NSString *type = [NSString stringWithFormat:@"%d",self.reportType];
    NSString *userName = [YJUserDefaultTool readUserName];
    NSString *md5Key = [YJUserDefaultTool readKeyID];
    params[@"action"] = @"set_report_add";
    params[@"makegold"] = @{@"username":userName,
                            @"report_id":self.reportID,
                            @"report_title":self.reportTitle,
                            @"type":type,
                            @"content":_content,
                            @"qqnum":@"",
                            @"user_info":userName,
                            @"phone_info":@"iOS",
                            @"md5_key":md5Key};
    NSString *url = THURL(@"report.php");
    
    [YJNetworkTool postWithUrl:url parameters:params success:^(id responseObject) {
        NSString *code = responseObject[@"return"][@"code"];
        if (code.integerValue == 200)
        {
            [MBProgressHUD showSuccess:@"举报成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [MBProgressHUD showError:responseObject[@"return"][@"message"]];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD showError:@"网络不佳，稍后重试" toView:self.view];
    }];

}
- (void)createView
{
    _advertButton = [self createButton:_arrays[0]];
    _eroticaButton = [self createButton:_arrays[1]];
    _illegalButton = [self createButton:_arrays[2]];
    _submitButton = [[UIButton alloc] init];
    _submitButton.backgroundColor = kUIColorFromRGB(0xff783c);
    [_submitButton setTitleColor:WHITECOLOR forState:UIControlStateNormal];
    [_submitButton setTitle:@"提交" forState:UIControlStateNormal];
    _submitButton.titleLabel.font = FONT(17);
    [_submitButton.layer setMasksToBounds:YES];
    [_submitButton.layer setCornerRadius:3.0];
    [_submitButton addTarget:self action:@selector(submitClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_submitButton];
    _advertButton.selected = YES;
    _content = _arrays[0];
    
    _advertButton.tag = 1;
    _eroticaButton.tag = 2;
    _illegalButton.tag = 3;
    
    [_advertButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(35);
        make.left.mas_equalTo(40);
        make.right.mas_equalTo(-80);
        make.height.mas_equalTo(32);
    }];
    [_eroticaButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_advertButton.mas_bottom).offset(40);
        make.left.equalTo(_advertButton.mas_left);
        make.right.equalTo(_advertButton.mas_right);
        make.height.equalTo(_advertButton.mas_height);
    }];
    [_illegalButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_eroticaButton.mas_bottom).offset(40);
        make.left.equalTo(_eroticaButton.mas_left);
        make.right.equalTo(_eroticaButton.mas_right);
        make.height.equalTo(_eroticaButton.mas_height);
    }];
    
    [_submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(60);
        make.right.mas_equalTo(-60);
        make.height.mas_equalTo(43);
        make.top.equalTo(_illegalButton.mas_bottom).offset(65);
    }];
}

- (UIButton *)createButton:(NSString *)title
{
    UIButton *button = [[UIButton alloc] init];
    button.titleLabel.font = FONT(15);
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:kUIColorFromRGB(0x666666) forState:UIControlStateNormal];
    UIEdgeInsets inset = UIEdgeInsetsMake(0, 20, 0, 0);
    [button setTitleEdgeInsets:inset];
    
    [button setImage:Image(@"manual_normal") forState:UIControlStateNormal];
    [button setImage:Image(@"manual_selected") forState:UIControlStateSelected];
    [button addTarget:self action:@selector(selectType:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    
    
   // button.backgroundColor = [UIColor orangeColor];
    return button;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
